package extract.knowledge;

import common.dao.couchdb.CouchDBKGFactory;
import extract.knowledge.concept.ConceptBatchMode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import common.dao.gremlin.TitanGraphDao;

/**
 * Created by Common on 9/10/16.
 */
public class KGBatchRun {

    final Logger logger = LoggerFactory.getLogger(KGBatchRun.class);

    public void cleanUpGraph(){
        new TitanGraphDao().cleanUpGraph();
        logger.info("[BatchRun] clean up graph success!");
    }

    public void createSchemaIndex(){
        // 1) concept
        ConceptBatchMode concept = new ConceptBatchMode(new CouchDBKGFactory(), new TitanGraphDao());
        concept.createSchemaIndex();
        logger.info("[BatchRun] created concept schema and index!");

        // 2) edge_class

        // 3) instance

    }


    public void importCouchDB(){
        // 1) concept
        ConceptBatchMode concept = new ConceptBatchMode(new CouchDBKGFactory(), new TitanGraphDao());
        concept.travelsalConceptDB();
        logger.info("[BatchRun] traversal db success!");

    }

    public static void cmdUsage(){
        System.err.println("Usage: BatchRun [ cleanup | create | import ] ");
        System.out.println("- cleanup : clean up graph, delete all schema and data!");
        System.out.println("- create  : create schema and index of graph. need to cleanup graph first!");
        System.out.println("- import  : import data from couchdb, and transform it to graph!");
        System.exit(1);
    }


    /******************************************
     *
     * @param args
     */
    public static void main(String[] args){
        final String CLEANUP = "cleanup";
        final String CREATE  = "create";
        final String IMPORT  = "import";
        if (null == args || 1 != args.length) {
            cmdUsage();
        }
        String cmd = args[0];
        if(cmd.equals( CLEANUP )){
            new KGBatchRun().cleanUpGraph();
        }
        else if(cmd.equals( CREATE )){
            new KGBatchRun().createSchemaIndex();
        }
        else if(cmd.equals( IMPORT )){
            new KGBatchRun().importCouchDB();
        }
        else{
            cmdUsage();
        }
        System.exit(1);
    }

}
